# import matplotlib if you wish to see the animation in gui
import pandas as pd
from matplotlib import pyplot as plt

import pynimate as nim

df = pd.DataFrame(
    {
        "time": ["1960-01-01", "1961-01-01", "1962-01-01"],
        "Afghanistan": [1, 2, 3],
        "Angola": [2, 3, 4],
        "Albania": [1, 2, 5],
        "USA": [5, 3, 4],
        "Argentina": [1, 4, 5],
    }
).set_index("time")

cnv = nim.Canvas()
# Interpolation frequency is 2 days
bar = nim.Barhplot.from_df(df, "%Y-%m-%d", "2d")
# use set_time to draw the datetime in the canvas
# here we are using a callback that returns datetime formatted in month, year
bar.set_time(callback=lambda i, datafier: datafier.data.index[i].strftime("%b, %Y"))
# add the bar plot to the canvas
cnv.add_plot(bar)
cnv.animate()
cnv.save("file", 24, "gif")
# plt.show()